import messageItemTemplate from "./MessageItem.html";
import { DomUtils } from "../../../utils/DomUtils";
export class MessageItem {
  constructor(data = {}) {
    this.data = {
      id: 0,
      sender: "",
      time: "",
      content: "",
      read: false,
      ...data,
    };
  }

  render() {
    const replacements = {
      sender: this.data.sender || "",
      time: this.data.time || "",
      content: this.data.content || "",
      readClass: this.data.read ? "read-message" : "unread-message",
    };

    let template = messageItemTemplate;
    Object.entries(replacements).forEach(([key, value]) => {
      template = template.replace(new RegExp(`{{${key}}}`, "g"), value);
    });

    // 使用 DomUtils 将模板字符串转换为 DOM 元素
    //return DomUtils.convertToDom(template);
    return template;
  }
}
